<template>
  <div class="register-area" data-info="查询项目信息">
    <el-button class="next" @click="handleNext" type="primary">
      下一步{{ stepInfo }}
    </el-button>

    <div class="step-comps-area" data-info="具体的业务">
      <component
        :is="curCompName"
        @handleSure="handleSure"
        inputTitle="药品首字母："
      >
         <p  class="middle item">请输入药品信息<span class="labelColor">首字母</span>查询</p> 
      </component>
    </div>
    <!--底部操作-->
    <PatientNumberOperate   :key="widget" @handleBack="handlePre" :time="120000" />
  </div>
</template>

<script>
import PatientNumberOperate from "@sc/DRCbiz/comps/patientNumberOperate/index.vue";
import InputLetterKeyboard from "@sc/DRCbiz/comps/input-letter-keyboard/index.vue";
import DrugInformationDetails from "@sc/DRCbiz/comps/Drug-Information-Details/index.vue";
import { v4 as uuid } from "uuid";
import { AndroidToWeb, buildParentApi } from "@/utils/designer/util";
let buildParent = buildParentApi();
export default {
  name: "QueryProjectInformation",

  componentName: "QueryProjectInformation",

  components: {
    PatientNumberOperate,
    InputLetterKeyboard,
    DrugInformationDetails
  },

  data() {
    return {
        widget: uuid(),
      steps: 1,
      curCompName: "CardType",
      compsOptions: {
        1: "InputLetterKeyboard",
        2: "DrugInformationDetails"
      },
    };
  },

  computed: {
    shownOperate() {
      return this.steps !== 1;
    },
    patientInfo() {
      return this.$store.getters["DRCbiz/getPatientInfo"];
    },
    // 步骤
    stepInfo() {
      return this.$store.getters["DRCbiz/getStepsInfo"];
    },
    //选中的卡片信息
    cardTypeInfo() {
      return this.$store.getters['DRCbiz/getCardTypeInfo']
    },
  },

  mounted() {
    this.$store.dispatch("DRCbiz/setCTDTimeInfo", 1200000);
  },

  methods: {
 
    handleSure(input) {
       let devInfo = JSON.parse(localStorage.getItem("deviceInfo"));
            // QueryMedicinesInfo  药品信息查询
            //   {
            //     "result": [{
            //         "medicineCode": "532986",
            //         "medicineName": "羟苯磺酸钙胶囊",
            //         "specifications": "0.5g",
            //         "price": "71.7500",
            //         "priceUnit": "粒",
            //         "producer": "宁夏康亚药业股",
            //         "type": "西药",
            //         "packagingUnit": "1",
            //         "miniUnit": "48",
            //         "chargelevel": "乙",
            //         "insurancecode": "XS01XAQ020E001020605911"
            //     }, {
            //         "medicineCode": "115219",
            //         "medicineName": "青蒿",
            //         "specifications": "1g",
            //         "price": "2.2100",
            //         "priceUnit": "克",
            //         "producer": "国产",
            //         "type": "中草药",
            //         "packagingUnit": "1",
            //         "miniUnit": "1000",
            //         "chargelevel": "甲",
            //         "insurancecode": "T000200628"
            //     }]
            // }
          let params = {
            Request: {
              deviceIp: devInfo.screenIp,
              flowId: uuid(),
              timestamp: this.$day().valueOf(),
              terminalNo: devInfo?.screenId, // 自助机设备终端	C	可空	根据医院实际情况
              method: "QueryMedicinesInfo",
              pinyinCode: input,
            },
          };
    
          let paramsInfo = this.$x2js.js2xml(params);
          buildParent.executeParentMethod(
            "axiosRep",
            paramsInfo,
            "QueryMedicinesInfo"
          );
    },
    async handleNext() {
       let stepInfo = parseInt(this.stepInfo);
      this.widget = uuid();
      if (stepInfo === 2) {
        await this.$store.dispatch("DRCbiz/setStepsInfo", 1);
      } else {
        await this.$store.dispatch("DRCbiz/setStepsInfo", ++stepInfo);
      }
    },

    // 返回上一层&首页
    async handlePre() {
      this.widget = uuid();
      let stepInfo = parseInt(this.stepInfo);
      if (stepInfo === 1) {
        await this.$router.push({
          path: `/DRCbizList`,
        });
      } else {
        await this.$store.dispatch("DRCbiz/setStepsInfo", --stepInfo);
      }
      switch (parseInt(this.stepInfo)) {
        case 2:
          let cardTypeInfo = this.cardTypeInfo;
          Reflect.set(cardTypeInfo, "cardNo", null);
          await this.$store.dispatch("DRCbiz/setCardTypeInfo", cardTypeInfo);
          buildParent.executeParentMethod("openScan");
          break;
      }
    },
  },

  watch: {
     // 步距
    stepInfo: {
      handler: function (val) {
        const self = this;
        self.widget = uuid();
        let cardTypeInfo = self.cardTypeInfo;
        if ( cardTypeInfo && val === 2) {
          // 电子医保特殊处理
          if (parseInt(cardTypeInfo?.id) === 29) {
            buildParent.executeParentMethod("MICode");
          } else {
            buildParent.executeParentMethod("openScan");
          }
        } else {
          buildParent.executeParentMethod("closeScan");
        }
        
        self.curCompName = Reflect.get(self.compsOptions, val);

      },
      deep: true,
      immediate: true,
    },
  },
};
</script>

<style scoped lang="scss">
@import "./assets/style";
</style>